package com.googlecode.mgwt.examples.uibinder.client.places;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;

public class ExamplePlace extends Place {
	public enum ID {
		UNKNOWN, BUTTON, CELL_LIST, HEADER_PANEL, INPUT, SLIDER;

		public String getName() {
			switch (this) {

			case HEADER_PANEL:
				return "Header Panel";

			case BUTTON:
				return "Buttons";
			case CELL_LIST:
				return "Cell List";

			case INPUT:

				return "Input Elements";
			case SLIDER:
				return "Slider";
			default:
				return "Default";
			}
		}

		public static ID from(String token) {
			if (token == null || "".equals(token)) {
				return ID.UNKNOWN;
			}

			if (ID.HEADER_PANEL.name().equals(token)) {
				return ID.HEADER_PANEL;
			}
			if (ID.BUTTON.name().equals(token)) {
				return ID.BUTTON;
			}

			if (ID.CELL_LIST.name().equals(token)) {
				return ID.CELL_LIST;
			}

			if (ID.INPUT.name().equals(token)) {
				return ID.INPUT;
			}

			if (ID.SLIDER.name().equals(token)) {
				return ID.SLIDER;
			}

			return ID.UNKNOWN;
		}
	}

	private final ID id;

	public ExamplePlace(ID id) {
		this.id = id;
	}

	public ID getId() {
		return id;
	}

	public static class Tokenizer implements PlaceTokenizer<ExamplePlace> {

		@Override
		public ExamplePlace getPlace(String token) {

			return new ExamplePlace(ID.from(token));
		}

		@Override
		public String getToken(ExamplePlace place) {
			return place.getId().name();
		}

	}
}
